<?php

namespace App\Http\Middleware;

use App\Exceptions\ApiException;
use Closure;

class Request
{

    protected string $controllerNamespace ='App\Http\Controllers';
    protected string $requestNamespace ='App\Http\Requests';
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  \Closure $next
     * @return mixed
     * @throws ApiException
     */
    public function handle($request, Closure $next)
    {

        //构建请求参数验证类
//        $route = request()->route()->action;
//
//        if(isset($route['controller'])){
//            $controller = str_replace('/',"\\", $route['controller']);
//            if(strpos($controller,"\\")===0){
//                $controller = substr($controller,1);
//            }
//            $class = str_replace($this->controllerNamespace, $this->requestNamespace, $controller);         //替换命名空间
////            $args = explode('@',$class);
////            $class = $args[0];
////            $action  = lcfirst($args[1]);
//            $class = Str::replaceLast("Controller", "Request", $class);         //替换后缀
//            try{
//                /** @var FormRequest $app */
//                $app = app($class);
//            }catch (ValidationException $e){
//                throw new ApiException($e->getMessage());
//            }catch (BindingResolutionException $e){
//
//            }catch (\Exception $e){
//                throw $e;
//            }
//        }

        return $next($request);
    }

    /** 获取导航栏链接 */
//    protected function setNavbar()
//    {
//        view()->composer('layout.navbar', function ($view) {
//            $view->with('nav', Post::recent());
//        });
//    }
}
